package bancosys.tec.services.export.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.persist.persister.annotation.NaturalKey;

@Entity
@Table(name = "MOCK_ENTITY")
@Alias("MOCKE")
@SequenceGenerator(name = "SEQ_MOCK", sequenceName = "SEQ_MOCK")
@Documentation("TABELA DE TESTES.")
public class MockEntity extends PersistableBusinessObject {

    private Long id;

    private String value;

    private List<AssociatedMockEntity> references = new ArrayList<AssociatedMockEntity>();

    public MockEntity(String value) {
        this.value = value;
    }

    public MockEntity() {
    }

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_MOCK")
    @Column(name = "ID")
    @Documentation("TABELA DE TESTES.")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    @NaturalKey
    @Column(name = "VALUE")
    @Documentation("TABELA DE TESTES.")
    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @OneToMany(mappedBy = "mock")
    @Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    @Documentation("TABELA DE TESTES.")
    public List<AssociatedMockEntity> getReferences() {
        return this.references;
    }

    public void setReferences(List<AssociatedMockEntity> references) {
        this.references = references;
    }

    @Override
    public int hashCode() {
        return this.value.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        MockEntity other = (MockEntity) obj;
        if (this.value == null) {
            if (other.value != null) {
                return false;
            }
        } else if (!this.value.equals(other.value)) {
            return false;
        }
        return true;
    }
}